package com.webservice.querysta;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletContext;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;

import com.webservice.bean.QueryResult;
import com.webservice.bean.Student;
import com.webservice.bean.StudentPost;
import com.webservice.bean.Teacher;
import com.webservice.store.DataAdapter;

@Path("/query")
public class QueryWeb 
{
	@Context
	ServletContext servletContext;
	
	List<Teacher> querybean=null;
	List<Student> studentbean=null;
	List<StudentPost> studentpostbean=null;
	
	@Path("/viewteacher")	
	@GET
	@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON})
	public List<Teacher> getTeacherDetail(@QueryParam("MobileNO") String MobileNO,@QueryParam("UserType") String UserType)
	{
	
		querybean =new ArrayList<Teacher>();
		querybean.addAll(DataAdapter.getTeacherDetail(MobileNO,UserType).values());
		return querybean;
	}
	
	@Path("/viewstudent")	
	@GET
	@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON})
	public List<Student> getStudentDetail(@QueryParam("MobileNO") String MobileNO,@QueryParam("UserType") String UserType)
	{
		System.out.println(" View Student mobile no1"+MobileNO);
		studentbean =new ArrayList<Student>();
		studentbean.addAll(DataAdapter.getStudentDetail(MobileNO, UserType).values());
		System.out.println("studentbean="+studentbean);
		return studentbean;		
	}
	
	@Path("/viewstudentpost")	
	@GET
	@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON})
	public List<StudentPost> getStudentPostDetail(@QueryParam("TeacherID") String TeacherID,@QueryParam("UserType") String UserType)
	{
		studentpostbean =new ArrayList<StudentPost>();
		studentpostbean.addAll(DataAdapter.getStudentPostDetail(TeacherID, UserType).values());
		return studentpostbean;		
	}
	
	@Path("/add")
	@GET
	@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON})
	public List<QueryResult> InsertUser(@QueryParam("PostedStudentID") String PostedStudentID,
	@QueryParam("PostedTeacherID") String PostedTeacherID,@QueryParam("StudentQuestion") String StudentQuestion,
	@QueryParam("StudentQuestionType") String StudentQuestionType,@QueryParam("UserType") String UserType) 
	{			
		List<QueryResult> Queryresult = null ;		
		Queryresult = new ArrayList<QueryResult>();
		DataAdapter.PostedStudentID=PostedStudentID;
		DataAdapter.PostedTeacherID=PostedTeacherID;
		DataAdapter.StudentQuestion=StudentQuestion;
		DataAdapter.StudentQuestionType=StudentQuestionType;
		Queryresult.addAll(DataAdapter.getStudentQueriesStatus(UserType).values() );
		return Queryresult;
	}
	
	@Path("/addstudent")
	@GET
	@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON})
	public List<QueryResult> addStudent(@QueryParam("StudentName") String StudentName,
	@QueryParam("StudentCollege") String StudentCollege,
	@QueryParam("StudentCourse") String StudentCourse,@QueryParam("MobileNo") String MobileNo,
	@QueryParam("EmailID") String EmailID,@QueryParam("Password") String Password,
	@QueryParam("UserType") String UserType) 
	{			
		List<QueryResult> Queryresult = null ;		
		Queryresult = new ArrayList<QueryResult>();
		DataAdapter.StudentName=StudentName;
		DataAdapter.StudentCollege=StudentCollege;
		DataAdapter.StudentCourse=StudentCourse;
		DataAdapter.MobileNo=MobileNo;
		DataAdapter.EmailID=EmailID;
		DataAdapter.Password=Password;
		Queryresult.addAll(DataAdapter.insertQuery(UserType,servletContext).values() );
		return Queryresult;
	}
	
	@Path("/addteacher")
	@GET
	@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON})
	public List<QueryResult> addTeacher(@QueryParam("TeacherName") String TeacherName,
	@QueryParam("TeacherCollege") String TeacherCollege,
//	@QueryParam("TeacherQualification") String TeacherQualification,
	@QueryParam("TeacherDesignation") String TeacherDesignation,
	@QueryParam("MobileNo") String MobileNo,
	@QueryParam("EmailID") String EmailID,@QueryParam("Password") String Password,
	@QueryParam("UserType") String UserType) 
	{			
		List<QueryResult> Queryresult = null ;		
		Queryresult = new ArrayList<QueryResult>();
		DataAdapter.TeacherName=TeacherName;
		DataAdapter.TeacherCollege=TeacherCollege;
//		DataAdapter.TeacherQualification=TeacherQualification;
		DataAdapter.TeacherDesignation=TeacherDesignation;
		DataAdapter.MobileNo=MobileNo;
		DataAdapter.EmailID=EmailID;
		DataAdapter.Password=Password;
		
		Queryresult.addAll(DataAdapter.insertQuery(UserType,servletContext).values() );
		return Queryresult;
	}
	
	@Path("/replypost")
	@GET
	@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON})
	public List<QueryResult> addTeacher(@QueryParam("PostID") String PostID,
	@QueryParam("Answer") String Answer,@QueryParam("ViewPost") String ViewPost,@QueryParam("FileContent") String FileContent,	
	@QueryParam("UserType") String UserType) 
	{			
		List<QueryResult> Queryresult = null ;		
		Queryresult = new ArrayList<QueryResult>();
		DataAdapter.PostID=PostID;
		DataAdapter.Answer=Answer;
		DataAdapter.ViewPost=ViewPost;		
		DataAdapter.FileContent=FileContent;
		Queryresult.addAll(DataAdapter.UpdataQueryPost(UserType).values() );
		return Queryresult;
	}
	
	@Path("/viewansweredpost")
	@GET
	@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON})
	public List<StudentPost> addTeacher(@QueryParam("StudentID") String StudentID,
	@QueryParam("UserType") String UserType) 
	{			
		
		
		studentpostbean =new ArrayList<StudentPost>();
		DataAdapter.StudentID=StudentID;	
		studentpostbean.addAll(DataAdapter.AnswaredQuery(UserType).values());
		return studentpostbean;	
	}
}
